﻿		<div id="content">
		{if !($user.is_guest)}
			<div style="text-align:right;">
				<a class="super secondary small" id="newtopicbtn" href="{$APP_URL}/newtopic"><span>ตั้งกระทู้</span></a>
				<a class="super secondary small" id="replytopicbtn" href="#replytopic"><span>ตอบกระทู้</span></a> 
			{if $uid == $topics.topic_poster || $user.is_admin}
				<a class="super secondary small" id="deletetopicbtn" href="{$APP_URL}/topic/delete/{$topics.topic_id}" onclick="return setConfirm(this);"><span>ลบกระทู้</span></a> 
			{/if}
			</div>
			<div style="clear: both;">&nbsp;</div>
		{/if}
			<div class="post rounded">
				<div class="gift-share">
				{if !($user.is_guest) && $uid != $topics.topic_poster && $topics.can_gift}
					<a href="javascript:void(0)" class="gift-link" id="gift-topic-{$topics.topic_id}" title="ถูกใจ"><img src="{$APP_URL}/images/gift-16.png" align="top" /></a>
				{/if}
					<a href="{$share2twitter}" target="_blank" title="แชร์กระทู้นี้ไปยังทวิตเตอร์"><img src="{$APP_URL}/images/twitter_share.png" align="top" /></a>
					<a href="{$share2facebook}" target="_blank" title="แชร์กระทู้นี้ไปยังเฟซบุค"><img src="{$APP_URL}/images/facebook_share.png" align="top" /></a>
				</div>	
				<div class="avatar"><img src="{$APP_URL}/avatar/{$topics.avatar}" /></div>
				<h1 class="title"><img src="{$APP_URL}/images/icons/topic/{$topics.topic_icon}-32.png" align="top" /><a href="{$APP_URL}/topic/{$topics.topic_id}" title="{$topics.topic_title_raw}">{$topics.topic_title}</a></h1>
				<p class="meta">โดย <a href="{$APP_URL}/user/{$topics.topic_poster}" title="ดูโปรไฟล์ของ {$topics.realname}">{$topics.realname}</a> เมื่อ {$topics.topic_time}
					&nbsp;&bull;&nbsp; <a href="#comments" class="comments" title="มี {$posts_count} ความคิดเห็น">{$posts_count} ความเห็น</a>
				<div class="entry">
					{$topics.topic_text}
				</div>
			{if !empty($topics.edit_time)}
				<div class="edit-time">
					แก้ไขล่าสุดเมื่อ {$topics.edit_time}
				</div>
			{/if}
				<div id="gifted-topic-{$topics.topic_id}" class="gift-box">
			{if !empty($topic_gift)}
				<br /><br /><img src="{$APP_URL}/images/gift-16.png" align="top" /><span style="color:#588000"> {$gift_count} กิ้ฟท์โดย: </span>
				{$topic_gift}
			{/if}
				</div>
			{if !($user.is_guest)}
				<div class="manage">
					<a href="javascript:void(0)" class="quote-link" id="quote-topic-{$topics.topic_id}" title="อ้างข้อความจากกระทู้นี้"><img src="{$APP_URL}/images/comments.png" align="top" /></a>
				{if $topics.topic_poster == $uid || $user.is_admin}
					<a href="{$APP_URL}/topic/edit/{$topics.topic_id}" title="แก้ไขข้อความกระทู้นี้"><img src="{$APP_URL}/images/comment_edit.png" align="top" /></a><a href="{$APP_URL}/topic/delete/{$topics.topic_id}" onclick="return setConfirm(this)" title="ลบกระทู้นี้"><img src="{$APP_URL}/images/comment_delete.png" align="top" /></a>
				{/if}
				</div>
			{/if}
			</div>
			
		{if !($user.is_guest)}
			<script type="text/javascript" src="{$APP_URL}/js/bbeditor/ed.js"></script>
			<div id="post_preview" class="rounded">
				<div class="head">ตัวอย่าง</div>
				<div class="body"></div>
			</div>			
			<div class="replyform">
				<div class="content">
					<fieldset>
						<legend>ตอบกระทู้</legend>
						<form action="{$APP_URL}/post" method="POST" name="replytopic" id="replytopic">
							<input type="hidden" name="action" value="add">
							<input type="hidden" name="topic_id" value="{$topics.topic_id}">
							<input type="hidden" name="session" value="{$user.session_id}" />
							<script type="text/javascript">edToolbar('post_text', 'emos');</script>
							<div id="emos" class="emoticon">
								{foreach from=$emos key=txt item=img}<a href="javascript:void(0);" onclick="replaceText('{$txt}', $('post_text'));$('emos').setStyle('display', 'none')">{$img}</a>{/foreach}
							</div>
							<label for="post_text" class="inlined">ข้อความ</label>
							<textarea name="post_text" id="post_text" class="input-text validate['required']" cols="100" rows="10"></textarea>
							<button type="submit" class="super secondary small">ตกลง</button>
							<button class="super secondary small" id="preview-btn">แสดงตัวอย่าง</button>
							<button type="reset" class="super secondary small">ยกเลิก</button>
						</form>
					</fieldset>
				</div>
			</div>
		{literal}
			<script type="text/javascript">
			window.addEvent('domready', function(){
				new FormCheck('replytopic', {'trimValue': true});
				preview_init('preview-btn', 'post_text', 'post_preview', APP.TOKEN);
				quote_init(APP.TOKEN);
				gift_init(APP.TOKEN);
			});
			{/literal}
			</script>	
		{/if}
		{if !empty($posts)}
			<div id="comments">
				<div class="header">{$posts_count} ความคิดเห็น</div>
				{foreach from=$posts item=p}
				<div class="comment rounded" id="comment-{$p.counter}">
				{if !($user.is_guest)}
					<div class="manage">
					{if $uid != $p.poster_id && $p.can_gift}
						<a href="javascript:void(0)" class="gift-link" id="gift-post-{$p.post_id}" title="ถูกใจ"><img src="{$APP_URL}/images/gift-16.png" align="top" /></a>  
					{/if}	
						<a href="javascript:void(0)" class="quote-link" id="quote-post-{$p.post_id}" title="อ้างข้อความจากความคิดเห็นนี้"><img src="{$APP_URL}/images/comments.png" align="top" /></a> 
					{if $p.poster_id == $uid || $user.is_admin}
						<a href="{$APP_URL}/post/edit/{$p.post_id}" title="แก้ไขความคิดเห็นนี้"><img src="{$APP_URL}/images/comment_edit.png" align="top" /></a>
						<a href="{$APP_URL}/post/delete/{$p.post_id}" onclick="return setConfirm(this)" title="ลบความคิดเห็นนี้"><img src="{$APP_URL}/images/comment_delete.png" align="top" /></a>
					{/if}
					</div>
				{/if}
					<div class="avatar"><img src="{$APP_URL}/avatar/{$p.avatar}" /></div>
					<div class="meta">
						<p>ความคิดเห็นที่ <a href="{$APP_URL}/topic/{$p.topic_id}#comment-{$p.counter}">{$p.counter}</a></p>
						<p>โดย <a href="{$APP_URL}/user/{$p.poster_id}" title="ดูโปรไฟล์ของ {$p.realname}">{$p.realname}</a></p>
						<p>เมื่อ {$p.post_time}</p>
					</div>
					<div style="clear: both;">&nbsp;</div>
					<div class="entry">
						{$p.post_text}
					</div>
				{if !empty($p.edit_time)}
					<div class="edit-time">
						แก้ไขล่าสุดเมื่อ {$p.edit_time}
					</div>
				{/if}
					<div id="gifted-post-{$p.post_id}" class="gift-box">
					{if $p.gift_count}
						<br /><br /><img src="{$APP_URL}/images/gift-16.png" align="top" /><span style="color:#588000"> {$gift_count} กิ้ฟท์โดย: </span>
						{$p.gift_text}
					{/if}
					</div>
				</div>
				{/foreach}
			</div>
			<div id="comments-pagination" class="pagination"></div>
		{/if}
		{if !($user.is_guest) && $posts_count > 3}
			<div style="text-align:right;padding:5px 0 20px;">
				<a class="super secondary small" id="newtopicbtn" href="{$APP_URL}/newtopic"><span>ตั้งกระทู้</span></a>
				<a class="super secondary small" id="replytopicbtn" href="#replytopic"><span>ตอบกระทู้</span></a>
			</div>
		{/if}
			<div style="clear: both;">&nbsp;</div>
		</div>
		<script type="text/javascript" src="{$APP_URL}/combine.php?type=javascript&files=jquery.pagination.js"></script>
		{literal}
		<script type="text/javascript">
		var force = 1;
		var post_items = {};
		var post_per_page = 5;
		window.addEvent('domready', function(){
			post_items = $$('.comment');
			jQuery('#comments-pagination').pagination(post_items.length, {
				link_to: 'javascript:void(0);',
				items_per_page: post_per_page,
				num_display_entries: 10,
				callback: pageselectCallback,
				prev_text: 'ก่อนหน้า',
				next_text: 'ถัดไป'
			});			
		});
		function pageselectCallback(page_index, jq){
			var max_elem = Math.min((page_index + 1) * post_per_page, post_items.length);
			post_items.setStyle('display', 'none');
			for(var i = page_index * post_per_page; i < max_elem; i++){
				post_items[i].setStyle('display', 'block');
			}
			if(!force)
				new Fx.Scroll(window).toElement('comments');
			else
				force = 0;
		}
		</script>
		{/literal}
		<!-- end #content -->